<template>
  <div class="dialog-container">
    <div class="dialog-content">
      <!--搜索-->
      <div class="panel-container">
        <SearchUiNew ref="SearchUiNew" :searchFormArr="searchFormArr" @searchParma="searchParma"></SearchUiNew>
      </div>
      <!--数据信息-->
      <div class="panel-container no-margin">
        <el-table stripe :data="dataList" size="mini" :header-cell-style="{ background: '#F5F5F5', color: '#000000' }" ref="table" style="width: 100%" v-loading="dataListLoading">
          <af-table-column align="center" header-align="center" show-overflow-tooltip label="采集时间" prop="created_time" width="200"></af-table-column>
          <af-table-column align="center" header-align="center" show-overflow-tooltip label="信息标题(原始)" prop="title" width="200"></af-table-column>
          <af-table-column align="center" header-align="center" show-overflow-tooltip label="详细内容(原始)" prop="desc" width="200"></af-table-column>
          <af-table-column align="center" header-align="center" show-overflow-tooltip label="联系人" prop="user_name"></af-table-column>
          <af-table-column align="center" header-align="center" show-overflow-tooltip label="来源" prop="source"></af-table-column>
          <af-table-column align="center" header-align="center" show-overflow-tooltip label="自动发" prop="is_auto">
            <template slot-scope="scope">
              {{ scope.row.is_auto === 1 ? '是' : '否' }}
            </template>
          </af-table-column>
          <af-table-column align="center" header-align="center" show-overflow-tooltip label="状态" prop="sts">
            <template slot-scope="scope"> {{ getPowerSts(scope.row.sts) }} </template>
          </af-table-column>
          <af-table-column align="center" header-align="center" show-overflow-tooltip label="申领人" prop="do_man_name"></af-table-column>
          <af-table-column align="center" header-align="center" show-overflow-tooltip label="最新处理时间" prop="do_man_time" width="200"></af-table-column>
          <af-table-column align="center" header-align="center" show-overflow-tooltip label="系统ID" prop="pub_id" width="280"></af-table-column>
        </el-table>
        <el-pagination
          small
          background
          :current-page="pageNumber"
          :page-size="pageSize"
          :page-sizes="[10, 20, 50, 100]"
          :total="pageTotal"
          @current-change="currentChangeHandle"
          @size-change="sizeChangeHandle"
          layout="total, sizes, prev, pager, next, jumper"
          style="margin-top: 20px; text-align: right"
        ></el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
import { apiSpiderList } from '@/api/assetsPublic'
import {} from '@/utils'

export default {
  name: 'DialogAILog',
  props: {
    time: Object,
  },
  components: {},
  data() {
    const powerStsList = [
      { value: 1, label: '待申领' },
      { value: 2, label: '待审核' },
      { value: 3, label: '已发布' },
      { value: 4, label: '已删除' },
    ]
    return {
      powerStsList,
      searchFormArr: [
        {
          fieldName: '来源:',
          type: 'input',
          field: 'source',
          placeholder: '请输入来源',
        },
        {
          fieldName: '状态:',
          type: 'select',
          field: 'sts',
          option: [
            { value: 0, label: '全部' },
            { value: 1, label: '待申领' },
            { value: 2, label: '待审核' },
            { value: 3, label: '已发布' },
            { value: 4, label: '已删除' },
          ],
          placeholder: '请选择',
        },
        {
          fieldName: '自动发:',
          type: 'select',
          field: 'is_auto',
          option: [
            { value: 0, label: '全部' },
            { value: 1, label: '是' },
            { value: 2, label: '否' },
          ],
          placeholder: '请选择',
        },
        {
          fieldName: '申领人：',
          type: 'input',
          field: 'do_man_name',
          placeholder: '请输入申领人',
        },
        {
          fieldName: '日期',
          type: 'timePicker',
          field: 'time',
          placeholder: '请选择日期',
          timeType: 'daterange',
          format: 'yyyy-MM-dd',
        },
      ],

      searchParams: {
        source: '',
        sts: '',
        is_auto: '',
        do_man_name: '',
        start_time: '',
        end_time: '',
      },
      dataList: [],
      pageNumber: 1,
      pageSize: 10,
      pageTotal: 0,
      dataListLoading: false,
    }
  },
  activated() {
    this.$refs.table.doLayout()
  },
  mounted() {
    this.init()
  },
  methods: {
    init() {
      if (this.time) {
        const { start_time, end_time } = this.time
        this.searchParams.start_time = start_time
        this.searchParams.end_time = end_time
        this.$nextTick(() => {
          this.$refs.SearchUiNew.setItemValue([{ key: 'time', value: [start_time, end_time] }])
        })
      } else {
        this.getDataList()
      }
    },
    // 获取数据列表
    getDataList() {
      this.dataListLoading = true
      const info = Object.assign({ pageNumber: this.pageNumber, pageSize: this.pageSize }, this.searchParams)
      apiSpiderList(info)
        .then((res) => {
          const { data, total } = res
          this.dataList = data
          this.pageTotal = total
          this.dataListLoading = false
          this.$refs.table.doLayout()
        })
        .catch((e) => {
          this.dataList = []
          this.pageTotal = 0
          this.dataListLoading = false
        })
    },
    // 列表查询
    searchParma(e) {
      // console.log(e)
      this.searchFormArr.forEach((item) => {
        if (item.field === 'time') return
        if (e[item.field]) {
          this.searchParams[item.field] = e[item.field]
        } else {
          this.searchParams[item.field] = ''
        }
      })
      if (e.time) {
        this.searchParams.start_time = e.time[0]
        this.searchParams.end_time = e.time[1]
      } else {
        this.searchParams.start_time = this.searchParams.end_time = ''
      }
      this.pageNumber = 1
      this.getDataList()
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val
      this.pageNumber = 1
      this.getDataList()
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageNumber = val
      this.getDataList()
    },
    // 获取状态
    getPowerSts(value) {
      const item = this.powerStsList.find((item) => item.value === value)
      if (item) {
        return item.label
      } else {
        return ''
      }
    },
  },
}
</script>

<style scoped lang="scss">
.panel-line {
  margin-bottom: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
</style>
